<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>~/gnustep/Frazione.m.html</title>
<meta name="Generator" content="Vim/7.2">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000"><font face="monospace">
<font color="#ff40ff">#import </font><font color="#ff6060">&lt;stdio.h&gt;</font><br>
<font color="#ff40ff">#import </font><font color="#ff6060">&quot;Frazione.h&quot;</font><br>
<br>
<font color="#ffff00">@implementation</font>&nbsp;Frazione <br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">void</font>) print {<br>
&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff6060">&quot;</font><font color="#ff40ff">%i</font><font color="#ff6060">/</font><font color="#ff40ff">%i</font><font color="#ff40ff">\n</font><font color="#ff6060">&quot;</font>, _numeratore, _denominatore );<br>
}<br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">void</font>) setNumeratore: (<font color="#00ff00">int</font>) n {<br>
&nbsp;&nbsp;&nbsp;&nbsp;_numeratore = n;<br>
}<br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">void</font>) setDenominatore: (<font color="#00ff00">int</font>) d {<br>
&nbsp;&nbsp;&nbsp;&nbsp;_denominatore = d;<br>
}<br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">void</font>) setNum: (<font color="#00ff00">int</font>) n setDen: (<font color="#00ff00">int</font>) d {<br>
&nbsp;&nbsp;&nbsp;&nbsp;_numeratore = n; <br>
&nbsp;&nbsp;&nbsp;&nbsp;_denominatore = d; <br>
}<br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">int</font>) numeratore {<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">return</font>&nbsp;_numeratore;<br>
}<br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">int</font>) denominatore {<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">return</font>&nbsp;_denominatore; <br>
}<br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">float</font>) toFloat {<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">return</font>&nbsp;_numeratore / (<font color="#00ff00">float</font>)_denominatore;<br>
}<br>
<br>
<font color="#8080ff">// a&nbsp;&nbsp;&nbsp;&nbsp; c&nbsp;&nbsp;&nbsp;&nbsp; a*d + c*b</font><br>
<font color="#8080ff">//--- + --- = -----------</font><br>
<font color="#8080ff">// b&nbsp;&nbsp;&nbsp;&nbsp; d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b*d</font><br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">id</font>) somma: (<font color="#00ff00">id</font>) frazione {<br>
&nbsp;&nbsp;&nbsp;&nbsp; _numeratore = _numeratore * [ frazione denominatore ]&nbsp;+ [ frazione numeratore ]&nbsp;* _denominatore;<br>
&nbsp;&nbsp;&nbsp;&nbsp; _denominatore *= [ frazione denominatore ];<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#ffff00">return</font>&nbsp;<font color="#ffff00">self</font>;<br>
}<br>
<br>
<font color="#8080ff">// a&nbsp;&nbsp;&nbsp;&nbsp; c&nbsp;&nbsp;&nbsp;&nbsp; a*d - c*b</font><br>
<font color="#8080ff">//--- - --- = -----------</font><br>
<font color="#8080ff">// b&nbsp;&nbsp;&nbsp;&nbsp; d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b*d</font><br>
<font color="#00ffff">-</font>(<font color="#00ff00">id</font>) sottrai: (<font color="#00ff00">id</font>) frazione {<br>
&nbsp;&nbsp;&nbsp;&nbsp;[<font color="#ffff00">self</font>&nbsp;somma: [frazione neg]];<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">return</font>&nbsp;<font color="#ffff00">self</font>;<br>
}<br>
<br>
<font color="#8080ff">//&nbsp;&nbsp;a&nbsp;&nbsp;&nbsp;&nbsp; c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a * d</font><br>
<font color="#8080ff">// --- : --- = -----------</font><br>
<font color="#8080ff">//&nbsp;&nbsp;b&nbsp;&nbsp;&nbsp;&nbsp; d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b * c</font><br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">id</font>) dividi: (<font color="#00ff00">id</font>) frazione {<br>
&nbsp;&nbsp;&nbsp;&nbsp;_numeratore&nbsp;&nbsp; *= [ frazione denominatore ];<br>
&nbsp;&nbsp;&nbsp;&nbsp;_denominatore *= [ frazione numeratore ];<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">return</font>&nbsp;<font color="#ffff00">self</font>;<br>
}<br>
<br>
<font color="#8080ff">//&nbsp;&nbsp;a&nbsp;&nbsp;&nbsp;&nbsp; c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a * c</font><br>
<font color="#8080ff">// --- x --- = -----------</font><br>
<font color="#8080ff">//&nbsp;&nbsp;b&nbsp;&nbsp;&nbsp;&nbsp; d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b * d</font><br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">id</font>) moltiplica: (<font color="#00ff00">id</font>) frazione {<br>
&nbsp;&nbsp;&nbsp;&nbsp;_numeratore&nbsp;&nbsp; *= [ frazione numeratore ];<br>
&nbsp;&nbsp;&nbsp;&nbsp;_denominatore *= [ frazione denominatore ];<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00">return</font>&nbsp;<font color="#ffff00">self</font>;<br>
}<br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">id</font>) semplifica {<br>
&nbsp;&nbsp;<font color="#ffff00">return</font>&nbsp;<font color="#ffff00">self</font>;<br>
}<br>
<br>
<font color="#00ffff">-</font>(<font color="#00ff00">id</font>) neg {<br>
&nbsp;&nbsp;_numeratore *= -<font color="#ff6060">1</font>; <br>
&nbsp;&nbsp;<font color="#ffff00">return</font>&nbsp;<font color="#ffff00">self</font>;<br>
}<br>
<br>
<font color="#ffff00">@end</font>&nbsp;<br>
</font></body>
</html>
